<template>
  <div>
    <template>
      <!--    <Tabs v-model="tabIndex" @on-click="changeTab" v-if="tabShow">-->
      <!--      <TabPane label="下级" name="tab1">-->
      <!--        <grid-level-info ref="gridLevel" :companyInfo="companyInfo" :choiceInfo="choiceInfo"></grid-level-info>-->
      <!--      </TabPane>-->
      <!--      <TabPane label="场所" name="tab2" v-if="choiceInfo.grade==='6'">-->
      <!--        <merchant ref="child" :pickInfo="choiceInfo"></merchant>-->
      <!--      </TabPane>-->
      <!--      <TabPane label="社会组织" name="tab3" v-if="choiceInfo.grade==='6'">-->
      <!--        <society ref="society" :pickInfo="choiceInfo"></society>-->
      <!--      </TabPane>-->
      <!--      <TabPane label="物件" name="tab4" v-if="choiceInfo.grade==='6'">-->
      <!--        <substance ref="substance" :pickInfo="choiceInfo"></substance>-->
      <!--      </TabPane>-->

      <!--      <TabPane label="添加管理人员" name="tab5" v-if="choiceInfo.grade === '5.5' || choiceInfo.grade === '6' ||  choiceInfo.grade === '7'">-->
      <!--        <manager ref="manager" :pickInfo="choiceInfo"></manager>-->
      <!--      </TabPane>-->
      <!--    </Tabs>-->
      <Tabs name="tab1" v-model="tabIndex" @on-click="changeTab" v-if="tabShow">

        <TabPane label="下级" name="tab1">
          <grid-level-info ref="gridLevel" :companyInfo="companyInfo" :choiceInfo="choiceInfo"></grid-level-info>
        </TabPane>

        <TabPane label="定线" tab="tab1" v-if="choiceInfo.grade==='6'" name="tab2">
          <Tabs name="tab1-2" @on-click="changeTabItem">
            <TabPane label="场所" tab="tab1-2">
              <merchant ref="child" :pickInfo="choiceInfo" v-if="choiceInfo.grade==='6'"></merchant>
            </TabPane>
            <TabPane label="社会组织" tab="tab1-2">
              <society ref="society" :pickInfo="choiceInfo" v-if="choiceInfo.grade==='6'"></society>
            </TabPane>
            <TabPane label="物件" tab="tab1-2" v-if="choiceInfo.grade==='6'">
              <substance ref="substance" :pickInfo="choiceInfo"></substance>
            </TabPane>
          </Tabs>
        </TabPane>
        <TabPane label="添加管理人员" tab="tab1" v-if="choiceInfo.grade === '6' ||  choiceInfo.grade === '7'" name="tab5">
          <manager ref="manager" :pickInfo="choiceInfo"></manager>
        </TabPane>
        <TabPane label="定人" tab="tab1" v-if="choiceInfo.grade === '5.5'" name="tab5">
          <newmanger ref="newManager" :pickInfo="choiceInfo"></newmanger>
        </TabPane>
        <TabPane label="定时" tab="tab1" v-if="choiceInfo.grade === '5.5'" name="tab6">
          <add-timer-manger ref="newManager" :pickInfo="choiceInfo"></add-timer-manger>
          <!--        <newmanger ref="newManager" :pickInfo="choiceInfo"></newmanger>-->
        </TabPane>
      </Tabs>
    </template>
  </div>
</template>

<script>
import GridLevelInfo from '../grid-level-info'
import PlaceInfo from '../place-info'
import Merchant from '../../../xian-page/grid-maintain-new/components/merchant-copy'
import Society from '../../../xian-page/grid-maintain-new/components/society-copy'
import Substance from '../../../xian-page/grid-maintain-new/components/substance-copy'
import Manager from '../../../xian-page/grid-maintain-new/components/manager'
import Newmanger from '../../../xian-page/grid-maintain-new/components/newmanger'
import AddTimerManger from '../../../xian-page/grid-maintain-new/components/addTimerManger'
export default {
  name: 'tableInfo',
  props: {
    choiceInfo: {
      type: Object
    },
    companyInfo: {
      type: Object
    }
  },
  components: { AddTimerManger, Manager, Substance, Society, Merchant, PlaceInfo, GridLevelInfo, Newmanger },
  data () {
    return {
      tabIndex: 0,
      tabShow: true
    }
  },
  methods: {
    changeTab (e) {
      console.log(this.choiceInfo.grade + '层机')
      if (e === 'tab1') {
        this.$refs.gridLevel.findGridLevelList()
      } else if (e === 'tab2') {
        // this.$refs.child.init()
      } else if (e === 'tab5') {
        if (this.choiceInfo.grade === '5.5') {
          this.$refs.newManager.init()
        } else {
          this.$refs.manager.init()
        }
      }
    },
    changeTabItem (e) {
      if (e === 0) {
        this.$refs.child.init()
      } else if (e === 1) {
        this.$refs.society.init()
      } else if (e === 2) {
        this.$refs.substance.init()
      }
    },
    reloadTab () {
      this.tabShow = false
      this.$nextTick(() => {
        this.tabShow = true
        this.tabIndex = 0
      })
    }
  },
  watch: {
    'choiceInfo.id': function (newV, oldV) {
      if (newV !== oldV) {
        try {
          this.reloadTab()
        } catch (e) {
          // console.log('choiceInfo.id', e)
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
